package solution._0040._0048;

/**
 * Created by chen_snow
 * Date: 2021/6/3 22:10
 * Description: 旋转图像
 */
public class Solution {
    public void rotate(int[][] matrix) {
        int length = matrix.length;

        int row, column = 0;
        if (length % 2 == 0) {
            row = column = length / 2;
        } else {
            row = length / 2;
            column = row + 1;
        }

        for (int i = 0; i < row; i++) {
            for (int j = 0; j < column; j++) {
                change(matrix, i, j, length);
            }
        }
    }

    public void change(int[][] matrix, int row, int column, int length) {
        int tmp = matrix[row][column];
        matrix[row][column] = matrix[length - column - 1][row];
        matrix[length - column - 1][row] = matrix[length - row - 1][length - column - 1];
        matrix[length - row - 1][length - column - 1] = matrix[column][length - row - 1];
        matrix[column][length - row - 1] = tmp;
    }
}
